package com.vimi8.ebb.sqlprovider;


import com.vimi8.ebb.model.Logistics;
import com.vimi8.ebb.model.ProductInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by think on 2016/7/7.
 */
public class LogisticsSqlProvider {
    private Logger logger =  LoggerFactory.getLogger(this.getClass());

    public String getInsertLogisticSql(Map<String, Object> parameters){
        StringBuilder sqlSb=new StringBuilder();
        List<Logistics> logisticsList=  ( List<Logistics>)parameters.get("logisticsList");
        sqlSb.append("INSERT INTO logistics(id, branch_name, branch_address, branch_address_code, affiliation_id, principal," +
                " contact, staffs, vehicles, trade_statistics_time, month_out_amount, month_in_amount, shipping_order_id, " +
                "shipping_address, shipping_address_code, delivery_area, delivery_area_code, create_time, update_time) VALUES");
        int count=0;
        for(Logistics logistics:logisticsList){
            sqlSb.append("('");
            sqlSb.append(logistics.getId()+"','");
            sqlSb.append(logistics.getBranchName()+"','");
            sqlSb.append(logistics.getBranchAddress()+"','");
            sqlSb.append(logistics.getBranchAddressCode()+"','");
            sqlSb.append(logistics.getAffiliationId()+"','");
            sqlSb.append(logistics.getPrincipal()+"','");
            sqlSb.append(logistics.getContact()+"','");
            sqlSb.append(logistics.getStaffs()+"','");
            sqlSb.append(logistics.getVehicles()+"','");
            sqlSb.append(logistics.getTradeStatisticsTime()+"','");
            sqlSb.append(logistics.getMonthOutAmount()+"','");
            sqlSb.append(logistics.getMonthInAmount()+"','");

            sqlSb.append(logistics.getShippingOrderId()+"','");
            sqlSb.append(logistics.getShippingAddress()+"','");
            sqlSb.append(logistics.getShippingAddressCode()+"','");
            sqlSb.append(logistics.getDeliveryArea()+"','");

            sqlSb.append(logistics.getDeliveryAreaCode()+"',");
            sqlSb.append("CURRENT_TIMESTAMP(),");
            sqlSb.append("CURRENT_TIMESTAMP()");

            if(logisticsList.size()-1>count){
                sqlSb.append("),");
            }else{
                sqlSb.append(");");
            }

            count++;
        }
        logger.info("sqlStr="+sqlSb.toString());
        return sqlSb.toString();
    }
    //getInsertTrainInfoSql

    public String getInsertLogisticBusinessSql(Map<String, Object> parameters){
        StringBuilder sqlSb=new StringBuilder();
        List<Logistics> logisticsList=  ( List<Logistics>)parameters.get("logisticsList");
        sqlSb.append("INSERT INTO logistics_business(id, logistics_id, month_out_amount, month_in_amount, statistics_time) VALUES");
        int count=0;
        for(Logistics logistics:logisticsList){
            sqlSb.append("('");
            sqlSb.append(UUID.randomUUID().toString()+"','");
            sqlSb.append(logistics.getId()+"','");
            sqlSb.append(logistics.getMonthOutAmount()+"','");
            sqlSb.append(logistics.getMonthInAmount()+"',");
            sqlSb.append("CURRENT_TIMESTAMP()");

            if(logisticsList.size()-1>count){
                sqlSb.append("),");
            }else{
                sqlSb.append(");");
            }

            count++;
        }
        logger.info("sqlStr="+sqlSb.toString());
        return sqlSb.toString();
    }
}
